class C
  class << self
    def a_class_method
      "C.a_class_method"
    end
  end
  def a_method
    "C#a_method"
  end
end

class D < C; end
obj = D.new
p obj.a_method # "C#a_method"

class << obj
  def a_singleton_method
    "D#a_singleton_method"
  end
end
p D.a_class_method # "C.a_class_method"
p obj.singleton_class # #<Class:#<D:0x00007fb9fe91a5b8>>
p obj.singleton_class.superclass # D
p D.singleton_class # #<Class:D>
p D.singleton_class.superclass # #<Class:C>
p C.singleton_class # #<Class:C>
p C.singleton_class.superclass # #<Class:Object>
p C.singleton_class.superclass&.superclass # #<Class:BasicObject>
p BasicObject.singleton_class # #<Class:BasicObject>
p BasicObject.singleton_class.superclass # Class
p Kernel.singleton_class # #<Class:Kernel>
p Kernel.singleton_class.superclass # Module
p obj.class.ancestors